package com.leetcode;

import java.util.PriorityQueue;

/**
 * 车子最少停靠几次问题
 *
 * @author wu
 * @create 2022-07-07-17:31
 */
public class SolutionMinRefuelStops {
    public static void main(String[] args) {
/*        int[][] arr = new int[2][1];
        arr[0][0] = 1;
        arr[1][0] = 3;
        System.out.println(minRefuelStops(100, 2, arr));*/
      //  System.out.println(minSubArrayLen(10, new int[]{1, 4, 5, 3, 2}));
      /*  String A = "hi你是乔戈里";
        System.out.println(A.length());
        int a  = 2 + 4 >> 1;
        System.out.println( a);*/

        Integer c = new Integer(1);

        Integer f = 1;
        if(c==f){
            System.out.println(1);
        }else {
            System.out.println(0);
        }
    }

    public static int minRefuelStops(int t, int start, int[][] ss) {
        PriorityQueue<Integer> q = new PriorityQueue<>((a, b) -> b - a);
        int n = ss.length, idx = 0;
        int remain = start, loc = 0, ans = 0;
        while (loc < t) {
            if (remain == 0) {
                if (!q.isEmpty() && ++ans >= 0) {
                    remain += q.poll();
                } else {
                    return -1;
                }
            }
            loc += remain;
            remain = 0;
            while (idx < n && ss[idx][0] <= loc) {
                q.add(ss[idx++][1]);
            }
        }
        return ans;
    }

    public static int minSubArrayLen(int t, int[] nums) {
        int n = nums.length, ans = n + 10;
        int[] sum = new int[n + 10];
        for (int i = 1; i <= n; i++) {
            sum[i] = sum[i - 1] + nums[i - 1];
        }
        for (int i = 1; i <= n; i++) {
            int s = sum[i], d = s - t;
            int l = 0, r = i;
            while (l < r) {
                int mid = l + r + 1 >> 1;
                if (sum[mid] <= d) {
                    l = mid;
                } else {
                    r = mid - 1;
                }
            }
            if (sum[r] <= d) {
                ans = Math.min(ans, i - r);
            }
        }
        return ans == n + 10 ? 0 : ans;
    }





}
